package com.book.bookshop.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.book.bookshop.entity.Adamin;
import com.book.bookshop.entity.User;
import com.book.bookshop.mapper.AdaminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class AdaminService extends ServiceImpl<AdaminMapper, Adamin>{
    @Autowired
    AdaminService adaminService;
    @Autowired
    AdaminMapper adaminMapper;
    public String loginCheck(Adamin loginUser, HttpSession session){
        LambdaQueryWrapper<Adamin> queryWrapper = Wrappers.<Adamin>lambdaQuery().eq(Adamin::getAdaminname,loginUser.getAdaminname());
        Adamin adamin = adaminMapper.selectOne(queryWrapper);
        try {
            if(adamin == null){
                return "101";//用户不存在
            } else {
                //判断密码
                if(loginUser.getAdaminpw().equals(adamin.getAdaminpw())){
                    session.setAttribute("adamin",adamin);
                    return "100";
                } else {
                    return "102";//密码不正确
                }
            }
        }catch (java.lang.NullPointerException e){
            return "101";
        }

    }
}

